<ion-header no-border align-title="center">
  <ion-toolbar color="primary">

    <ion-title mode="ios">
      <p class="header-title">Rent</p>
    </ion-title>

    <ion-buttons left>
      <button ion-button icon-only (click)="logout()">
        <ion-icon ios="ios-power" md="md-power"></ion-icon>
      </button>
    </ion-buttons>

    <ion-buttons end>
      <button ion-button icon-only (click)="presentActionSheet()">
        <ion-icon ios="ios-add" md="md-add"></ion-icon>
      </button>
    </ion-buttons>
  </ion-toolbar>

  <ion-toolbar no-border-top>
    <ion-segment [(ngModel)]="homeList">
      <ion-segment-button value="roomList" (ionSelect)="registerChangeList('roomList')">房间列表</ion-segment-button>
      <ion-segment-button value="buildList" (ionSelect)="registerChangeList('buildList')">地址列表</ion-segment-button>
    </ion-segment>
  </ion-toolbar>

</ion-header>

<ion-content padding [ngSwitch]="homeList">

  <ion-list *ngSwitchCase="'roomList'">
    <ion-item-sliding *ngFor="let room of rooms">
      <ion-item (click)="registerViewRoom(room)">
        <h2>{{ room.room_name }}</h2>
        <p>{{ room.build_address }}</p>
      </ion-item>
      <ion-item-options>
        <button ion-button color="primary" (click)="registerEditRoom(room)">
          <ion-icon name="create"></ion-icon>
          编辑
        </button>
        <button ion-button color="danger" (click)="registerRemoveRoom(room)">
          <ion-icon name="trash"></ion-icon>
          删除
        </button>
      </ion-item-options>
    </ion-item-sliding>
  </ion-list>

  <ion-list *ngSwitchCase="'buildList'">
    <ion-item-sliding *ngFor="let build of builds">
      <ion-item>
        <h2>{{ build.build_address }}</h2>
        <p>电费单价：{{build.build_electricity_price}}元/度</p>
        <p>水费单价：{{build.build_water_price}}元/立方米</p>
      </ion-item>
      <ion-item-options>
        <button ion-button color="primary" (click)="registerEditBuild(build)">
          <ion-icon name="create"></ion-icon>
          编辑
        </button>
        <button ion-button color="danger" (click)="registerRemoveBuild(build)" >
          <ion-icon name="trash"></ion-icon>
          删除
        </button>
      </ion-item-options>
    </ion-item-sliding>
  </ion-list>

  <ion-infinite-scroll (ionInfinite)="doInfinite($event)">
    <ion-infinite-scroll-content></ion-infinite-scroll-content>
  </ion-infinite-scroll>

</ion-content>
